package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.CheckItemService;
import com.itheima.service.MemberService;
import com.itheima.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author 14463
 * @date ${DATA} 11:46
 */



@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    //根据手机号查询会员
    @Override
    public Member findByTelephone(String telephone) {
        System.out.println(234);
        return memberDao.findByTelephone(telephone);
    }

    //新增会员
    @Override
    public void add(Member member) {
        String password = member.getPassword();
        if (password != null) {
            member.setPassword(MD5Utils.md5(password));
        }
        memberDao.add(member);
    }
    /**
     *
     * @param month
     * @return  每个月的用户数的集合
     */
    @Override
    public List<Integer> findMemberCountByMonth(List<String> month) {
        List<Integer> memberCountByMonth= new ArrayList<>();
        for (String s : month) {
            Integer memberCount = memberDao.findMemberCountByMonth(s + ".31");
            memberCountByMonth.add(memberCount);

        }

            return memberCountByMonth;
    }
}
